//
// Created by 史振江 on 7/30/23.
//

#ifndef SPUSHRTMP_SVIDEOCHANNEL_H
#define SPUSHRTMP_SVIDEOCHANNEL_H

#include <thread>
#include <x264.h>
#include "defind-util.h"

typedef void (*VideoCallBack)(RTMPPacket*);

class SVideoChannel {
private:
    pthread_mutex_t mutex;// 互斥锁
    int width;
    int height;
    int fps;
    int bitrate;

    // y 的长度
    int y_len;

    // uv 的长度
    int uv_len;

    // x264编码器
    x264_t *videoEncode = 0;

    // 每一张图片
    x264_picture_t *pic_in = 0;

    // 函数指针回调rtmpPacket
    VideoCallBack videoCallBack;

public:
    SVideoChannel();

    ~SVideoChannel();

    void setVideoCallBack(VideoCallBack);

    void initX264Encode(int width, int height, int fps, int bitrate);

    void encodeData(signed char *data);

    void sendSpsWithPPS(uint8_t sps[100], uint8_t pps[100], int len, int len1);

    void sendIWithP(int type, int payload, uint8_t *payload1);

};


#endif //SPUSHRTMP_SVIDEOCHANNEL_H
